define(['jquery', 'bootstrap', 'backend', 'table', 'form','editable'], function ($, undefined, Backend, Table, Form,undefined) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/student/index' + location.search,
                    add_url: 'user/student/add',
                    edit_url: 'user/student/edit',
                    del_url: 'user/student/del',
                    multi_url: 'user/student/multi',
                    import_url: 'user/student/import',
                    table: 'user_student',
                }, queryParams: function (params) {
                    // 自定义搜索条件
                    var filter = params.filter ? JSON.parse(params.filter) : {};
                    var op = params.op ? JSON.parse(params.op) : {};
                    if (Config.user_id && Config.user_id != 'null') {
                        // console.log("user_id",Config.user_id)
                        filter.user_id = Config.user_id;
                        op.user_id = "=";
                    }
                    params.filter = JSON.stringify(filter);
                    params.op = JSON.stringify(op);
                    // console.log(params);
                    return params;
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: true,
                exportDataType: "auto",
                exportTypes: [ 'excel'],
                exportOptions: {
                    fileName: '学员导出_' + Moment().format("YYYY-MM-DD"),
                    preventInjection: false,
                    mso: {
                        onMsoNumberFormat: function (cell, row, col) {
                            return !isNaN($(cell).text()) ? '\\@' : '';
                        },
                    },
                    ignoreColumn: [0, 'operate'] //默认不导出第一列(checkbox)与操作(operate)列
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        // {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'gender', title: __('Gender'),  searchList: {1: __('Male'), 0: __('Female')}, formatter: Table.api.formatter.label},
                        // {field: 'gender', title: __('Gender')},
                        {field: 'birthday', title: __('Birthday'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'school_name', title: __('School_name'), operate: 'LIKE'},
                        {field: 'id_card', title: __('IdCard'), operate: 'LIKE'},
                        {field: 'remark', title: __('备注')},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
